﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

public partial class SearchResultsControl : System.Web.UI.UserControl {
	protected Dictionary<User, List<Schedule>> schedules;

	protected List<Schedule> inputSchedules = new List<Schedule>();

	public List<Schedule> InputSchedules {
		get { return this.inputSchedules; }
		set { this.inputSchedules = value; }
	}

    protected void Page_Load(object sender, EventArgs e) {
		//Search for schedules
        if (this.IsPostBack == true)
        {
            return;
        }
		this.inputSchedules.Sort(new ScheduleComparer());

		//Convert to map form
		this.schedules = new Dictionary<User, List<Schedule>>();
		foreach (Schedule schedule in this.inputSchedules) {
			List<Schedule> scheduleList = null;
			if (this.schedules.ContainsKey(schedule.User)) {
				scheduleList = this.schedules[schedule.User];
			}
			if (scheduleList == null) {
				scheduleList = new List<Schedule>();
				this.schedules[schedule.User] = scheduleList;
			}

			scheduleList.Add(schedule);
		}
    }
}
